
/**   
 * @Title: ShiroPrincipal.java 
 * @Package: com.aft.jlgh.common.security 
 * @Description: TODO
 * @author Mandarava  
 * @date 2016年5月19日 上午9:05:32 
 * @version 1.3.1 
 * @Email wuyan1688@qq.com
 */


package com.infoland.common.security;

import java.io.Serializable;
import java.util.List;

import com.infoland.modules.main.model.Admin;
import com.infoland.modules.main.model.Menu;


/** 
 * 自定义shiro认证主体
 * @author Mandarava
 * @date 2016年5月19日 上午9:05:32 
 * @version V1.3.1
 */

public class ShiroPrincipal implements Serializable {

	
	/** 
	 * @Fields serialVersionUID: 
	 */
	  	
	private static final long serialVersionUID = -9051566290786697126L;
	
	private Admin user;
	//用户权限列表
	private List<String> authorities;
	//用户角色列表
	private List<String> roles;
	//是否已授权。如果已授权，则不需要再从数据库中获取权限信息，减少数据库访问
	//这里会导致修改权限时，需要重新登录方可有效
	private boolean isAuthorized = false;
	
	private List<Menu> menus;
	
	public ShiroPrincipal(Admin user){
		if(user != null){
			this.user = user;
			this.isAuthorized = Boolean.TRUE;
			this.authorities = user.getAdminAuthorities();
			this.roles = user.getAdminRolesMark();
			this.menus = user.getAdminMenus();
		}
	}
	
	public Admin getUser() {
		return user;
	}
	public void setUser(Admin user) {
		this.user = user;
	}
	public List<String> getAuthorities() {
		return authorities;
	}
	public void setAuthorities(List<String> authorities) {
		this.authorities = authorities;
	}
	public List<String> getRoles() {
		return roles;
	}
	public void setRoles(List<String> roles) {
		this.roles = roles;
	}
	public boolean isAuthorized() {
		return isAuthorized;
	}
	public void setAuthorized(boolean isAuthorized) {
		this.isAuthorized = isAuthorized;
	}
	
	/**
	 * <shiro:principal/>标签显示中文名称
	 */
	@Override
	public String toString() {
	    return user.getAName();
	}

	public List<Menu> getMenus() {
		return menus;
	}

	public void setMenus(List<Menu> menus) {
		this.menus = menus;
	}
}
